<%@ page import="java.sql.*" %>
<%--
  Created by IntelliJ IDEA.
  User: xujc
  Date: 7/6/15
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息</title>
  <meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
</head>
<body>
  <h1>学生信息</h1>
<%
  try {
    Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/test");
    PreparedStatement preparedStatement = con.prepareStatement("SELECT * FROM student WHERE sid=?");
    preparedStatement.setString(1, request.getParameter("id"));
    ResultSet resultSet = preparedStatement.executeQuery();
    if (resultSet.next()) {
      String sid = resultSet.getString("sid");
      String name = resultSet.getString("name");
      int grade = resultSet.getInt("grade");
      out.print("姓名: ");
      out.println(name);
      out.print("学号: ");
      out.println(sid);
      out.print("成绩: ");
      out.println(grade);
    } else {
      out.println("学生不存在");
    }
    con.close();
  } catch (SQLException e) {
    e.printStackTrace();
  }
%>
</body>
</html>
